<template>
  <div class="app-container">
      <el-form ref="industrialForm" :rules="rules" :model="industrialForm" label-position="left" label-width="70px" style="width: 400px; margin-left:50px;">
        <el-form-item label="文件" prop="attach">
        <SingleExcelUpload v-model="industrialForm.attach" />
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="industrialForm.remark" :autosize="{ minRows: 2, maxRows: 4}" type="textarea" placeholder="备注" />
        </el-form-item>
      </el-form>
    <div slot="footer" class="dialog-footer" v-loading="loading">
      <el-button @click="handleCannel()">
        取消
      </el-button>
      <el-button type="primary" @click="saveIndustrial()">
        确认
      </el-button>
    </div>
  </div>
</template>

<script>
import {  importIndustrial,  } from '@/api/knowledge/industrial'
import waves from '@/directive/waves' // waves directive
import SingleExcelUpload from '@/components/Upload/SingleExcelUpload' // secondary package based on el-pagination

export default {
  name: 'ComplexTable',
  components: { SingleExcelUpload },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      loading:false,
      tableKey: 0,
      collegeOptions:[],
      schoolOptions:[],
      industrialForm: {
        identity: undefined,
        remark: '',
        school_identity: 0,
        attach: '',
        status: {
          value:1
        }
      },
      rules: {
        type: [{ required: true, message: 'type is required', trigger: 'change' }],
        timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
        title: [{ required: true, message: 'title is required', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.loadSchoolList()
  },
  methods: {
    handleCannel() {
      this.$router.push({ path: 'industrial' })
    },
    loadSchoolList() {
      getSchoolUsableList().then(response => {
        if(response.status === 200){
          this.schoolOptions = response.data.list
        }
      })
    },
    loadCollegeList() {
      const FormData = {
        "school_identity":this.industrialForm.school_identity
      }
      getCollegeUsableList().then(response => {
        if(response.status === 200){
          this.collegeOptions = response.data.list
        }
      })
    },
    saveIndustrial() {
      this.$refs['industrialForm'].validate((valid) => {
        if (valid) {
          this.loading = true;
          importIndustrial(this.industrialForm).then((response) => {
              this.loading = false;
              if (response.status === 200) {
                this.$message({
                  message: '操作Success',
                  type: 'success'
                })
                this.$router.push({ path: 'industrial' })
              } else {
                this.$message({
                  message: response.msg,
                  type: 'error'
                })
              }
          })
        }
      })
    }
  }
}
</script>
